<?php
/**
 * Ora 后台管理模块
 *  @author  lan7
 * 	@qq 278058275
 *  @url www.lan7.net
 */

if(!defined('IN_ORA')) {
	exit('Access Denied');
}
$GLOBALS['__msg_tpl__'] = "admin/msg.html";
#session_set_cookie_params(20*60);
session_start();
$GLOBALS["act"] = empty($GLOBALS["act"])?"index":$GLOBALS["act"];
/**
 * 上传模块
 */
if($GLOBALS['act']=='upload'){
	if(!isset($_SESSION["admin"])){
		exit('Access Denied');
	}
	$s = "";
	if(isset($_POST['submit'])){
		if($_FILES["userfile"]['error'][0]!=4){
			import("lib.upload");
			$up = new Upload("jpg|gif|png");
			if(!$up->errInfo){
				$img = $up->files[0]["urlPath"];
			}
		}
		if(isset($img)&&isset($GLOBALS['_param']['mth'])){
			$s = "<script>parent.".$GLOBALS['_param']['mth']."('$img');</script>";
		}
	}
	$GLOBALS['tpl']->assign('purl',get_url());
	$GLOBALS['tpl']->assign("js",$s);
	$GLOBALS['tpl']->display('admin/upload.html');
}
if(!isset($_SESSION["admin"])){
	redirect("common-login");
}

/**
 * 管理首页
 */
else if($GLOBALS["act"]=="index"){
	$GLOBALS["tpl"]->display("admin/index.html");
}

/**
 * 左侧导航
 */
else if($GLOBALS["act"]=="left"){
	$GLOBALS["tpl"]->display("admin/left.html");
}

/**
 * 默认页
 */
else if($GLOBALS["act"]=="main"){
	$GLOBALS["tpl"]->display("admin/main.html");
}

/**
 * 系统配置管理
 */
else if($GLOBALS["act"]=="config"){
	$GLOBALS['tpl']->assign("uname",$_SESSION['admin']['username']);
	$GLOBALS['tpl']->assign("config",$GLOBALS['db']->getOne("select * from config order by id desc limit 1"));
	$GLOBALS['tpl']->display("admin/config.html");
}

/**
 * 管理帐号
 */
else if ($GLOBALS["act"]=='admin') {
	if(isset($_POST["submit"])){
		if(strlen(trim($_POST["passwd"]))==0){
			showMsg("请输入当前密码!",$_SERVER["HTTP_REFERER"],1);
		}else if(md5($_POST["passwd"])!=$_SESSION['admin']['passwd']){
			showMsg("密码错误!",$_SERVER["HTTP_REFERER"],1);
		}else if(strlen(trim($_POST["npasswd"]))==0){
			showMsg("请输入新密码!",$_SERVER["HTTP_REFERER"],1);
		}else if(strlen(trim($_POST["npasswd1"]))==0){
			showMsg("确认密码不能为空!",$_SERVER["HTTP_REFERER"],1);
		}else if($_POST["npasswd"]!=$_POST["npasswd1"]){
			showMsg("两次密码不一致!",$_SERVER["HTTP_REFERER"],1);
		}else{
			$sql = "update ".tn('members')." set passwd = '".md5($_POST['npasswd'])."' where uname = '".$_SESSION['admin']['username']."'";
			if($GLOBALS['db']->query($sql)){
				$msg['result'] = "操作成功!";
				unset($_SESSION["admin"]);
				showMsg("操作成功,请重新登录!",parse_uri("common-login"),true);
			}
		}
	}
	$GLOBALS["tpl"]->display("admin/admin.html");
}

/**
 * 清除系统缓存
 */
else if($GLOBALS["act"]=="cache"){
	io::removeDir(ROOT_PATH."archive");
	io::removeDir(ROOT_PATH."cache");
	showMsg("缓存清除成功!",parse_uri("admin-main|true"),1);
}
?>